'use strict';

/**
 * @ngdoc function
 * @name webApp.controller:ForgetpasswordCtrl
 * @description
 * # ForgetpasswordCtrl
 * Controller of the webApp
 */
angular.module('webApp')
  .controller('ForgetpasswordCtrl', function ($scope,$location,$ionicPopup,popBox,jqLite,promiseForgetPassword) {
    $scope.$on('$stateChangeSuccess',function(){
      $scope.user = [];
      $scope.submit = function(){
        if($scope.user.forgetPassword){
          var text = $scope.user.forgetPassword;
          var myPop = $ionicPopup.show({
            template: '<div ng-controller="popImg">' +
            '<div class="changeImg" ng-click="changeImg()">' +
            '<img class="imagesGet" ng-src="{{imagesGet}}" data="{{token}}">' +
            '</div>' +
            '<input class="checkoutText" type="text">' +
            '</div>',
            title: '请填写验证码',
            subTitle: '',
            scope: $scope,
            buttons: [
              { text: '取消' },
              {
                text: '<b>提交</b>',
                type: 'button-positive',
                onTap: function(e) {
                  promiseForgetPassword.forgetPassword(text,jqLite.$('checkoutText')[0].value,jqLite.$('imagesGet')[0].attributes.data.nodeValue).then(function(){
                    popBox.showConfirm('提示','已成功发至您邮箱！');
                    $location.path('/root/signIn');
                  });
                }
              }
            ]
          });
        }
        else{
          popBox.showConfirm('警告','请正确填写信息！');
        }
      };
    });
  });
